<?php

namespace Common\Model;
use think\Model;

class UserGoodsAttrModel extends BaseModel{

	//追加属性
    public $append = [
        'add_time_text',
        'dis_price',
        'price',
        'stock',
      
	];
    /**
     * 折扣价数据调整
     * @param $value
     * @param $data
     * @return mixed
    */
    public function getDisPriceAttr($value, $data){
        $dis_price = floatval($data['dis_price']);
		return $dis_price;
    }
   
    /**
     * 单价数据调整
     * @param $value
     * @param $data
     * @return mixed
    */
    public function getPriceAttr($value, $data){
        $price = floatval($data['price']);
		return $price;
    }
    /**
     * 总库存
     * @param $value
     * @param $data
     * @return mixed
    */
    public function getStockAttr($value, $data){
        $stock = $this->getStock($data['id']);
		return floatval($stock);
    }

    //获取总库存
    function getStock($id){
        $model = M('user_kuerp_warehouse_product');
        $wdata['item_id'] = $id;
        $stock =  $model->where($wdata)->sum('stock') ? : 0;
        return $stock;
    }
}